package com.hotel.user.mapper;

import com.hotel.common.utils.DBTools;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Repository
public class UserRoleMapper {

    public int insert(Long userId, Long roleId) {
        String sql = "INSERT INTO user_role (user_id, role_id, created_at) VALUES (?, ?, ?)";
        return DBTools.update(sql, userId, roleId, LocalDateTime.now());
    }

    public int deleteByUserIdAndRoleId(Long userId, Long roleId) {
        String sql = "DELETE FROM user_role WHERE user_id = ? AND role_id = ?";
        return DBTools.update(sql, userId, roleId);
    }

    public int deleteByUserId(Long userId) {
        String sql = "DELETE FROM user_role WHERE user_id = ?";
        return DBTools.update(sql, userId);
    }

    public int deleteByRoleId(Long roleId) {
        String sql = "DELETE FROM user_role WHERE role_id = ?";
        return DBTools.update(sql, roleId);
    }
}